<!--
 * @Author: zengwj
 * @Date: 2021-10-29 16:39:32
 * @LastEditors: zengwj
 * @LastEditTime: 2021-11-03 11:00:32
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //       0 <= s.length <= 3000
      // s 仅由数字组成
      var restoreIpAddresses = function (s) {
        let res = [];
        let path = [];
        let backtracking = function (start) {
          const len = path.length;
          if(len > 4) return;
          if(len===4&& start === s.length){
            res.push(path.join('.'))
            return
          }
          for (let i = start; i < s.length; i++) {
              let str = s.slice(start, i + 1);
              if(str.length>3||+str>255) break;
              if(str.length>1&&str[0]==='0')break;
              path.push(str);
              backtracking( i + 1);
              path.pop();
          }
        };
        backtracking(0);
        return res;
      };
      console.log(restoreIpAddresses('010010'));
    </script>
  </body>
</html>
